//////////////////////////////////////////////////
// EASIM project
// easim.mobi.Mobility
// 2007/6/6 3:15 PM
// Cong Liu
// gzcong@gmail.com

// Copyright (C) 2007
// All rights reserved.
// Refer to LICENSE of JIST (Java In Simulation Time) for terms and conditions of use.

package easim.mobi;

import easim.net.Field;
import easim.net.Node;
import easim.net.Clock;
import easim.net.Timer;

import jist.runtime.JistAPI;
import jist.swans.Constants;

public abstract class Mobility implements Timer, JistAPI.DoNotRewrite
{

  public static class Movement implements JistAPI.DoNotRewrite
  {
    public long delay;
    public float x;
    public float y;
  }

  public abstract Movement next();

  protected Node node;

  public Mobility(Node node) {
    this.node = node;
  }

  public void start() {
    timeout();
  }

  public void stop() {
    Clock.cancel(this);
  }

  public void timeout() {
    if (! node.isOnField()) return;
    Movement movement = next();
    Field.move(node, movement.x, movement.y);
    Clock.start(this, movement.delay, false);
  }

}
